<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /* 先请求A 再请求B 再请求C */
    
        async function getData() {
          const user = await new Promise((resolve, reject) => {
            console.log("A数据开始请求....")
            try {
              // throw new Error("A错误")
              setTimeout(() => {
                console.log("A数据请求成功");
                const user = {
                  username: "laoliu"
                }
                resolve(user)
              }, 2000)
            } catch (e) {
              reject(e.message)
            }
          });
    
          const sex = await new Promise((resolve, reject) => {
            console.log("B数据开始请求....")
            try {
              // throw new Error("B错误")
              setTimeout(() => {
                console.log("B数据请求成功");
                const sex = {
                  sex: "男"
                }
                resolve({
                  ...user,
                  ...sex
                })
              }, 2000)
            } catch (e) {
              reject(e.message)
            }
          });
    
    
          const age = await new Promise((resolve, reject) => {
            console.log("C数据开始请求....")
            try {
              // throw new Error("C错误")
              setTimeout(() => {
                console.log("C数据请求成功");
                const age = {
                  age: 18
                }
                resolve({
                  ...sex,
                  ...age
                })
              }, 2000)
            } catch (e) {
              reject(e.message)
            }
          });
    
    
          //最后异步的操作 我们可以不用await 也会最后执行
          console.log("完整的数据是", age);
    
        }
    
    
        getData()
      </script>
</body>
</html>